#include "namedPipe.hpp"

int main()
{
    NamedPipe fifo(comm_path, Creater);
    if (!fifo.OpenForRead())
    {
        std::cout << "OpenForRead failed" << std::endl;
        return 1;
    }
    // 对于读端而言，如果我们打开文件，但是写端还没来，则进程会阻塞在open调用中，直到对方打开
    // 进程同步
    std::cout << "server open named pipe done" << std::endl;
    sleep(3);
    while (true)
    {
        std::string message;
        int n = fifo.ReadNamedPipe(&message);
        if (n > 0)
        {
            std::cout << "Client say>" << message << std::endl;
        }
        else if (n == 0)
        {
            std::cout << "Client quit, Server too!" << std::endl;
            break;
        }
        else
        {
            std::cout << "fifo.ReadNamedPipe Error" << std::endl;
            break;
        }
    }

    return 0;
}